package com.focusai.efairy.utils;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;

/**
 * Created by luo_guangwen on 2017/7/7.
 */

public class AndroidUtils {

    /** 获取客户端版本 **/
    public static String getVersionName(Context context) {
        PackageManager pm = context.getPackageManager();
        String versionName = "";
        try {
            PackageInfo pi = pm.getPackageInfo(context.getPackageName(), 0);
            versionName = pi.versionName;
        } catch (PackageManager.NameNotFoundException e) {
            return versionName;
        }
        return versionName;
    }

    /** 获取客户端版本 **/
    public static int getVersionCode(Context context) {
        PackageManager pm = context.getPackageManager();
        int versionName = 1;
        try {
            PackageInfo pi = pm.getPackageInfo(context.getPackageName(), 0);
            versionName = pi.versionCode;
        } catch (PackageManager.NameNotFoundException e) {
            return versionName;
        }
        return versionName;
    }
}
